
Norm.Introspection = {
	
	sqliteMasterModel : new Norm.Model({
		name : "sqlite_master",
		fields : {
			type : new Norm.Fields.String(),
			name : new Norm.Fields.String(),
			tbl_name : new Norm.Fields.String(),
			rootpage : new Norm.Fields.Integer(),
			sql : new Norm.Fields.String()
		}
	}),
	
	doesTableExist : function() {
		
		var argsLength = arguments.length;
		var qmarks = [];
		var vals = ["table"];							// used instead of ["table"].concat(arguments) since it doesn`t work as expected
		for (var i = 0; i < argsLength; i++) {
			qmarks.push("?");
			vals.push(arguments[i]);	
		}
		var query = ["sqlite_master.type =? AND sqlite_master.name IN (", qmarks.join(","), ")"].join("");
		
		return Norm.Introspection.sqliteMasterModel.count(query, vals) == argsLength;
	}
};
